<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <%- include common %>
</head>
<body>
    <%- include('head',{title:'login',username:''})  %>
    <div class="container">
        <h2 class="text-primary" >登录-login</h2>
        <div class="row">
            <div class="col-md-4 ">
                <form  >
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input type="text" value="<%- username %>"   name="username" class="form-control" id="username" placeholder="Username">
                    </div>
                    <div class="form-group">
                        <label for="password">密码</label>
                        <input type="password" value="<%- password %>" name="password" class="form-control" id="password" placeholder="Password">
                    </div>
                    <button type="button" class="btn btn-success" onclick="hanlderlogin()">登录</button>
                    <button type="reset" class="btn btn-danger">重置</button>
                </form>
            </div>
        </div>
    </div>
    <%- include foot %>

    <script >
        // 登录 
        function hanlderlogin(){
            $.ajax({
                url:"/users/login",
                type:"post",
                data:{
                    username:$("#username").val(),
                    password:$("#password").val(),
                },
                success(res){
                    console.log(res);
                    alert(res.msg);
                    if(res.type){
                        location.href="/"
                    }else{
                        location.reload();
                    }
                }
            })
        }
    </script>
</body>
</html>